<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <title>学生信息主页面</title>
    </head>
    <body>
    <center>
    <?php
    include "common\menu.php";
    require "common\conn.php";
    ?>

    <h3>学生信息浏览</h3>
    <form action="" method="">
        <input type="text" name="select" placeholder="请输入查询信息" required>
        <input type="submit" value="查询">
    </form>
    <table border="1" width="800" cellspacing="0" cellpadding="5" bordercolor="red" style="font-family:'楷体';">
        <tr>
            <th>学号</th>
            <th>姓名</th>
            <th>性别</th>
            <th>电话</th>
            <th>年龄</th>
            <th>学院</th>
            <th colspan="2">操作</th>
        </tr>
    <?php
    $sql = "SELECT * FROM stu";

    if(isset($_GET['select'])) {
        $select = $_GET['select'];
        $sql .= " where stu_no like '%$select%' 
        or stu_name like '%$select%' 
        or gender like '%$select%' 
        or telephone like '%$select%' 
        or age like '%$select%' 
        or college like '%$select%'"; //拼接上方的sql语句,模糊查询
    }

    $result = $pdo->query($sql); //执行sql,query返回一个PDOstatement对象
    $stu_arr = $result->fetchall(PDO::FETCH_ASSOC); //返回一个存放学生数据的二维数组

    foreach ($stu_arr as $stu) {
        echo "<tr>";
        echo "<td>{$stu['stu_no']}</td>";
        echo "<td>{$stu['stu_name']}</td>";
        echo "<td>{$stu['gender']}</td>";
        echo "<td>{$stu['telephone']}</td>";
        echo "<td>{$stu['age']}</td>";
        echo "<td>{$stu['college']}</td>";
        echo "<td><a href='update.php?stu_no={$stu['stu_no']}'>修改</a></td>";
        echo "<td><a href='delete.php?stu_no={$stu['stu_no']}'>删除</a></td>";
        echo "</tr>";
    }
    ?>
    </table>
    </center>
    </body>
</html>